<template>
<div>
    <fieldset class="layui-elem-field layui-field-title">
        <legend>修改集装信息</legend>
    </fieldset>
    <form class="layui-form ">

        <div class="layui-form-item">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-block" style="width:250px">
                <input type="text" name="name" v-model="data.name" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态 </label>
            <div class="layui-input-block" style="width:250px">
                <select name="type" id="" style="width:250px" >
                    <option value="1">普通</option>
                </select>
            </div>
            <!-- <div class="layui-input-block" style="width:250px">
                <input type="text" name="type" v-model="data.type" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
            </div> -->
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="submit">立即提交</button>
                <button class="layui-btn layui-btn-primary" @click="$parent.back">返回</button>
            </div>
        </div>
    </form>
</div>
</template>

<script>
let qs = require('qs');
export default {
    data() {
        return {
            guid: "",
            data: {

            }
        }
    },
    mounted() {
        let that = this;

        layui.use(['form'], function () {
            var form = layui.form,
                layer = layui.layer;
            that.getList(this.$parent);
            //赋予完成 重新渲染select
            form.render('select');
            form.on('submit(submit)', function (data) {
                let loader = layer.load();
                let params = {
                    name: that.data.name,
                    type: that.data.type,
                    guid: that.data.guid,
                    operatorid: that.data.operatorid
                }
                $.ajax({
                    url: '/sales/Boxtype!addOrupdate.action',
                    data: params,
                    type: "post",
                    dataType: "json",
                    success: function (res) {
                        if (res.msg == "success") {
                            that.toast("修改成功");
                            that.$parent.switchPage('WlExtras');
                        } else {
                            that.toast("系统错误");
                        }
                    },
                    complete: function () {
                        layer.close(loader);
                    }
                });
                return false;
            });
        })

    },
    created() {

    },
    methods: {
        getList(id) {
            this.$post("/sales/Boxtype!list.action", qs.stringify({
                    guid: this.$parent.gid
                }))
                .then(res => {
                    this.data = res.data.info.rows[0]
                })
                .catch(error => {

                })
        }
    }
}
</script>
